/*
* $Id: JournalSettings.cpp 49 2010-03-02 17:13:58Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "JournalSettings.h"
#include "../SettingControlIds.h"
#include "../DinIntDefined.h"
#include "Components/Components.h"

#define JOURNAL_REG_NAME	_T("Software\\Apiary\\JournalSettings")

CJournalSettings::CJournalSettings(CJournalComponent* pJournalComponents)
: CSettings(JOURNAL_CAPTION_ID, JOURNAL_REG_NAME, TRUE){
	m_pJournalComponents = pJournalComponents;
	Init();
}
CJournalSettings::~CJournalSettings(){}

std::map<std::tstring, std::vector<Parameter> > CJournalSettings::GetParameters(){
	std::map<std::tstring, std::vector<Parameter> > aMapParameters;
	std::vector<Parameter> aParameters;

	//static_header     
	aParameters.push_back(Parameter(TYPE, HEADER));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(STATIC_HEADER_ID, aParameters));

	//static_style
	aParameters.clear();
	aMapParameters.insert(aMapParameters.end(), std::make_pair(STATIC_STYLE_ID, aParameters));

	//combo_style
	std::vector<std::tstring> aStyles;
	if(m_pJournalComponents)
		aStyles = m_pJournalComponents->GetStyleNames();
	for(std::vector<std::tstring>::iterator it = aStyles.begin(); it != aStyles.end(); it++)
		aParameters.push_back(Parameter(COMBO_STRING, *it));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(COMBO_STYLE_ID, aParameters));

	return aMapParameters;
}

std::map<std::tstring, std::tstring> CJournalSettings::GetDefaultStates(){
	std::map<std::tstring, std::tstring> aDefault;
	std::vector<std::tstring> styleNames;
	if(m_pJournalComponents)
		styleNames = m_pJournalComponents->GetStyleNames();
	if(!styleNames.empty())
		aDefault.insert(aDefault.end(), std::make_pair(COMBO_STYLE_ID, styleNames.at(0)));
	return aDefault;
}

std::map<std::tstring, std::tstring> CJournalSettings::GetStates(){
	std::map<std::tstring, std::tstring> aStates;
	aStates.insert(aStates.end(), std::make_pair(STATIC_HEADER_ID, IApplication::GetApp()->GetLanguageManager()->GetString(SETTINGS_ID)));
	aStates.insert(aStates.end(), std::make_pair(STATIC_STYLE_ID, IApplication::GetApp()->GetLanguageManager()->GetString(STYLE_JOURNAL_ID)));
	aStates.insert(aStates.end(), std::make_pair(COMBO_STYLE_ID, IApplication::GetApp()->GetLanguageManager()->GetString(_ttoi(CCommonFunction::GetRegValue(JOURNAL_REG_NAME, COMBO_STYLE_ID).c_str()))));
	return aStates;
}

std::vector<Window> CJournalSettings::GetWindows(){
	std::vector<Window> aWindows;
	aWindows.push_back(Window(STATIC, 10, 0, 415, 23, SS_CENTER, IApplication::GetApp()->GetLanguageManager()->GetString(SETTINGS_ID), STATIC_HEADER_ID));
	aWindows.push_back(Window(STATIC, 10, 30, 415, 15, SS_LEFT, IApplication::GetApp()->GetLanguageManager()->GetString(STYLE_JOURNAL_ID), STATIC_STYLE_ID));
	aWindows.push_back(Window(COMBO_BOX, 10, 45, 415, 20, CBS_DROPDOWNLIST, _T(""), COMBO_STYLE_ID));
	return aWindows;
}

std::tstring CJournalSettings::GetSaveValue(const std::tstring& strValueName, const std::tstring& strValue, bool& bSave){
	TCHAR value[10];
	bSave = TRUE;
	int nId;
	if(strValueName == COMBO_STYLE_ID)
		nId = m_pJournalComponents->GetView(strValue)->GetStyleView()->GetStyleId();
	_itot_s(nId, value, 10, 10);
	return value;
}

void CJournalSettings::PostSave(){
//	m_pApp->GetChangeManager()->SetChange(SETTINGS, CHANGE_JOURNAL_SETTINGS);
}